<?php

namespace app\home\controller;

use app\common\controller\Home;

class Game extends Home
{
    public function index()
    {
        // $url                = ; //接口地址
        // $keyword            = urldecode();
        // $keyword            = urlencode($keyword); //查询关键字，需以URLEncode方式进行编码，totalList为渠道下所有游戏数据
        $data['channelId']  = 12633; //渠道号
        $data['query']      = 'totalList';
        $data['orderby']    = 'update'; //排序，update--按更新日期排序，hot--按热门排序
        $data['page']       = 1; //页号，默认为1
        $data['pageNum']    = 100; //每页返回数据条数，默认为50，最多返回500条

        $post_data = json_encode($data);

        // echo $post_data;

        // 使用CURL拉取数据
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'https://tui.guopan.cn/api/queryGames.php');
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        $response = curl_exec($ch); //返回结果，数据为JSON格式
        curl_close($ch);
        $list = json_decode($response);
        // echo $response; //测试，打印返回数据
        return json($list);
    }
}
